# encoding: utf-8

''' 多层感知器 '''

from sklearn.neural_network import MLPRegressor
import numpy as np

def poly(X, Y):
    imax = 0
    idx = 0
    train = None
    for kernel in zip(np.random.randint(1, 60, 600)):
        trainer = MLPRegressor(
            hidden_layer_sizes=kernel,  activation='relu', solver='adam', alpha=0.0001, batch_size='auto',
            learning_rate="adaptive", power_t=0.5, shuffle=False, learning_rate_init=.1,
            tol=0.0001, verbose=False, momentum=0.9, nesterovs_momentum=True,
            early_stopping=False,beta_1=0.9, beta_2=0.999, epsilon=1e-08)
        t = trainer.fit(X, Y)
        mlp_score = t.score(X, Y)
        print("Poly回归得分: ", mlp_score, f'隐藏层大小{kernel}')
        if mlp_score>imax:
            imax = mlp_score
            idx = kernel
            train = t
    print(f"得分最高的组是{idx}: {imax}")
    return train